﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace theguineasyndrome.Utils
{
    public class PolarCoordinates
    {
        public static Vector2 fromCartesian(Vector2 v)
        {
            Vector2 w;

            if (v.X < 0 && v.Y == 0)
            {
                w.X = -v.X; // r
                w.Y = (float)Math.PI; // theta
            }
            else
            {
                w.X = v.Length(); // r
                w.Y = (float)(2 * Math.Atan(v.Y / (v.X + w.X))); // theta
            }

            return w;
        }

        public static Vector2 toCartesian(Vector2 v)
        {
            Vector2 w;
            w.X = (float)(Math.Cos(v.Y) * v.X);
            w.Y = (float)(Math.Sin(v.Y) * v.X);
            return w;
        }
    }
}
